from google.appengine.ext import webapp
from support import render_page, get_game
import logging

class FormHandler(webapp.RequestHandler):    

    # Get Abstract methods
    ######################

    def get_template(self, request, game):
        pass

    def update_parameters(self, request, game, parameters):
        return parameters

    # Post Abstract methods
    #######################
    
    def update_game(self, request, game):
        pass
    
    def get_destination(self, request, game):
        pass

    # Implemented Methods
    #####################
    
    def get(self):
        logging.info('Form called')
        request = self.request
        game = get_game()
        template = self.get_template(request, game)
        web_page_parameters = {
           "this_page":request.path,
           "game":game,
        }
        web_page_parameters = self.update_parameters(request, game, web_page_parameters)
        web_page = render_page(template, web_page_parameters)
        self.response.out.write(web_page)
    
    def post(self):
        request = self.request
        game = get_game()
        self.update_game(request, game)
        game.update()
        destination = self.get_destination(request, game)
        self.redirect(destination)
        